package org.niux.aims.action;

import javax.annotation.Resource;

import org.niux.aims.common.web.AimsBaseAction;
import org.niux.aims.service.IAccountService;
import org.niux.aims.service.ILogsService;
import org.niux.aims.vo.AccountVO;

/**
 * 
 * Copyright (c) 2009,niux<br>
 * All rights reserved.<br>
 * 
 * 文件名称：UpdatePassword.java<br>
 * 摘    要：修改帐户密码类<br>
 * <br>
 * 当前版本：<br>
 * 作    者：铭显 Email: <a href="mailto:liangmingxian@gmail.com">liangmingxian@gmail.com</a><br>
 * 完成日期：@since 2013-9-2<br>
 * <br>
 * 取代版本：<br>
 * 原作者  ：<br>
 * 完成日期：@since Oct 22, 2009<br>
 */
public class UpdatePassword extends AimsBaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1325653596448155163L;
	
	@Resource(name="accountService")
	private IAccountService accountService;
	
	@Resource(name="logsService")
	private ILogsService logsService;
	
	private String id;
	private AccountVO account;
	private String newPassword;
	
	/**
	 * 
	 * 方法概述：页面渲染
	 * 描述：页面渲染
	 * @return
	 * 返回类型：String
	 * 修改人：梁铭显
	 * 修改时间：2013-9-2
	 */
	public String showPage(){
		logsService.addLog("【"+((AccountVO)super.getSession().get("account")).getName()+"】进入密码修改界面");
		account = accountService.findById(Integer.parseInt(id));
		return SUCCESS;
	}
	
	/**
	 * 
	 * 方法概述：修改密码
	 * 描述：修改密码
	 * @return
	 * 返回类型：String
	 * 修改人：梁铭显
	 * 修改时间：2013-9-2
	 */
	public String updatePassword(){
		AccountVO accountVo = new AccountVO();
		accountVo.setId(Integer.parseInt(id));
		accountVo.setPassword(newPassword);
		
		accountService.updatePassword(accountVo);
		
		logsService.addLog("【"+((AccountVO)super.getSession().get("account")).getName()+"】修改密码");
		super.getRequest().setAttribute("result", "Success");
		
		return SUCCESS;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public AccountVO getAccount() {
		return account;
	}

	public void setAccount(AccountVO account) {
		this.account = account;
	}

	public String getNewPassword() {
		return newPassword;
	}

	public void setNewPassword(String newPassword) {
		this.newPassword = newPassword;
	}
}
